package cn.javabb.core.base;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;

/**
 * 查询对象,后面的查询类都继承这个类
 */
@Data
@Accessors(chain = true)
@EqualsAndHashCode(callSuper = false)
public class BaseQuery {

    public final static int DEFAULT_PAGE_SIZE = 10;

    private int page = 1;
    private int size = 0;
    // 针对layui table的分页参数
    private int limit = 0;
    private int pageStart = 0;
    private String orderField;
    private String orderDirection;
    private String keyword;

    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date startDate;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    private Date endDate;

    public int getSize(){
        return size>0 ? size :limit>0?limit:DEFAULT_PAGE_SIZE;
    }
    public int getPageStart(){
        return page > 0 ? (page-1)*getSize():0;
    }
}
